//
//  JSTNewServer.m
//  KYKJPackDemo
//
//  Created by 01 on 17/6/1.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTNewServer.h"

@implementation JSTNewServer

+ (void) requestPhoneModifyCode:(NSString *)phoneNum success:(void (^)(NSDictionary *))successBlock failure:(void (^)(NSString *failureStr))failureBlock{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    parmas[@"apkname"] = [JSTSystemInfo applicationIdentifier];
    parmas[@"appname"] = [JSTSystemInfo applicationName];
    parmas[@"appkey"] = [JSTSystemInfo userKey];
    parmas[@"mobile"] = phoneNum;
    [JSTHttpClient sendRequest:[NSString stringWithFormat:@"%@/%@", kAppServerForHttps, modifyCodeInterface] requestMethod:AFRequestMethodGet parameters:parmas success:^(NSDictionary *responseObject) {
        if (successBlock) successBlock(responseObject);
    } failure:^(NSUInteger statusCode, NSString *error) {
        if (failureBlock) failureBlock(error);
    }];
}

/**
 提交动态接口

 @param imageData 动态图片集合
 @param content 动态文本
 @param dataDic 回调成功
 @param errStr 回调错误提示
 */
+ (void)requestCommitDynamic:(NSArray *)imageData getContent:(NSString *)content success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    [dic setValue:content forKey:@"content"];
    
    [JSTHttpClient sendRequest:[NSString stringWithFormat:@"%@/%@", kAppServerForHttps, PublishDynamicInterface] requestMethod:AFRequestMethodPost parameters:dic imageArray:imageData success:^(id responseObject)
    {
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1)
        {
            dataDic([dic valueForKey:@"data"]);
        }else errStr([dic valueForKey:@"message"]);
    } failure:^(NSUInteger statusCode, NSString *error)
    {
        DLog(@"----- str = %@", error);
    }];
}

/**
 提交评论
 
 @param commentDic 评论集合
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestCommitComment:(NSDictionary *)commentDic success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:commentDic];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    
    [JSTHttpClient sendRequest:[NSString stringWithFormat:@"%@/%@", kAppServerForHttps, SubmitComentInterface] requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject)
     {
         NSDictionary *dic = responseObject;
         if ([[dic valueForKey:@"status"] integerValue] == 1)
         {
             dataDic([dic valueForKey:@"data"]);
         }else
         {
             errStr([dic valueForKey:@"message"]);
         }
     } failure:^(NSUInteger statusCode, NSString *error)
     {
         errStr(error);
     }];
}

/**
 动态详情

 @param dynamicId 动态ID
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestDynamicDetails:(NSString *)dynamicId success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:[KYSystemInfoTool appKey] forKey:@"appKey"];
    [dic setValue:[KYSystemInfoTool bundleID] forKey:@"apkName"];
    [dic setValue:dynamicId forKey:@"id"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, statusDetailUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1) {
            dataDic([dic valueForKey:@"data"]);
        } else {
            errStr([dic valueForKey:@"message"]);
        }
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

#warning - OK(修改过后)
/**
 *  登录请求
 */
+ (void)requestLoginWithPhoneNum:(NSString *)phoneNum modifyCode:(NSString *)modifyCode success:(void(^)(NSDictionary *dataDict))successBlock failure:(void(^)(NSString  *failureStr))failureBlock{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    parmas[@"mobile"] = phoneNum;
    parmas[@"code"] = modifyCode;
    parmas[@"apkname"] = [KYSystemInfoTool bundleID];
    parmas[@"appkey"] = [KYSystemInfoTool appKey];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, loginUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodGet parameters:parmas success:^(NSDictionary *responseObject) {
        if (successBlock) successBlock(responseObject);
    } failure:^(NSUInteger statusCode, NSString *error) {
        if (failureBlock) failureBlock(error);
    }];
}

/**
 我的动态
 
 @param requestDic 请求所需的 new（最新）、hot（最热）、page（页数）、pageSize（每页容量）集合
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestMyDynamic:(NSDictionary *)requestDic success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:requestDic];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, mineStatusUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodGet parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1) {
            dataDic([dic valueForKey:@"data"]);
        } else {
            errStr([dic valueForKey:@"message"]);
        }
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

/**
 删除动态
 
 @param dynamicId 动态ID
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestDeleteDynamic:(NSString *)dynamicId success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:dynamicId forKey:@"id"];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, deleteMineStatus];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        dataDic(dic);
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

/**
 编辑用户信息
 
 @param dic 请求所需的 name（昵称）sex（性别）birth_month（生日月份）birth_day（生日日期）sign（签名）icon（头像）集合
 @param imageData 提交图片
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestEditUserInfo:(NSDictionary *)dic getImageData:(NSArray *)imageData success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:dic];
    [dict setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, editUserInfoUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodGet parameters:dict imageArray:imageData success:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1) {
            dataDic([dic valueForKey:@"data"]);
        } else {
            errStr([dic valueForKey:@"message"]);
        }
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

/**
 所有动态
 
 @param requestDic 请求所需的 new（最新）、hot（最热）、page（页数）、pageSize（每页容量）集合
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestAllDynamic:(NSDictionary *)requestDic success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:requestDic];
    [dic setValue:[KYSystemInfoTool appKey] forKey:@"appKey"];
    [dic setValue:[KYSystemInfoTool bundleID] forKey:@"apkName"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, allStatusUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1) {
            dataDic([dic valueForKey:@"data"]);
        }else {
            errStr([dic valueForKey:@"message"]);
        }
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

/**
 用户信息
 
 @param userId 用户ID
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestUserInfo:(NSString *)userId success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:userId forKey:@"userid"];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, userInfoUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1) {
            dataDic([dic valueForKey:@"data"]);
        }else {
            errStr([dic valueForKey:@"message"]);
        }
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

/**
 删除评论
 
 @param dynamicId 动态ID
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestDeleteComment:(NSString *)dynamicId success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:dynamicId forKey:@"id"];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, deleteCommentUrl];
    
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        if ([[dic valueForKey:@"status"] integerValue] == 1) {
            dataDic([dic valueForKey:@"data"]);
        } else {
            errStr([dic valueForKey:@"message"]);
        }
    } failure:^(NSUInteger statusCode, NSString *error) {
        errStr(error);
    }];
}

/**
 点赞取消赞
 
 @param dynamicId 动态ID
 @param dataDic 回执成功数据
 @param errStr 回执错误提示
 */
+ (void)requestFabulous:(NSString *)dynamicId success:(void (^)(NSDictionary *))dataDic error:(void (^)(NSString *))errStr
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:dynamicId forKey:@"id"];
    [dic setValue:[KYUserAccountTool shareUserData].token forKey:@"token"];
    NSString *url = [NSString stringWithFormat:@"%@/%@", kAppServerForHttps, likeBtnClickUrl];
    [JSTHttpClient sendRequest:url requestMethod:AFRequestMethodPost parameters:dic success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        dataDic(dic);
    } failure:^(NSUInteger statusCode, NSString *error) {
        
    }];
}

/**
 根据城市请求天气参数
 
 @param successsBlock 成功回调
 @param failureBlock 失败回调
 */
+ (void) requestLocalWeatherInfoSuccess:(void(^)(NSDictionary *dataDic))successsBlock
                                failure:(void(^)(NSString *errStr))failureBlock{
    NSString *city = [[[JSTLocation sharedInstace].address componentsSeparatedByString:@"/"] lastObject];
    NSDictionary *parames = @{@"city":city};
    [JSTHttpClient sendRequest:weatherInfoUrl requestMethod:AFRequestMethodGet parameters:parames success:^(id responseObject) {
        NSDictionary *dic = responseObject;
        if (successsBlock) successsBlock(dic);
    }failure:^(NSUInteger statusCode, NSString *error) {
        if (failureBlock) failureBlock(error);
    }];
}

@end
